
var arr=[0, 1, 2];

function findOutlier2(arr){
  if(arr.length<3){
    return null;
  }

var oddArr=arr.filter(x=>x%2==0);
var evenArr=arr.filter(x=>x%2!=0);
return  oddArr.length==1?oddArr[0]:evenArr[0];

}




function findOutlier(array){
  if(array.length<3){
    return null;
  }
  var numType //0偶数 1奇数
  var oddNumCount=0;
  var evenNumCount=0;
  for(var i=0;i<3;i++){
    var num=array[i];
     if(num%2==0){
       evenNumCount++;
     }else {
       oddNumCount++;
     }
  }
  //判断outlier类型
  if(evenNumCount>oddNumCount){
    numType=1; //奇数为outlier
  }else {
    numType=0; //偶数为outlier
  }

  if(numType===1){
    for(num of array){
      if(num%2!=0){
        return num;
      }
    }
  }else {
    for(num of array){
      if(num%2==0){
        return num;
      }
    }
  }
}

document.write(findOutlier(arr));
document.write("<br>")



var a = [3,4,5,6,7,8,9,0,12,23,45,90,1,2,2];


var str="Welcome to Microsoft! "
str=str + "We are proud to announce that Microsoft has "
str=str + "one of the largest Web Developers sites in the world."

document.write(str.replace(/Microsoft/g, "W3School"));
document.write('<br>');
document.write('<br>');

var text = "javascript Tutorial";
text.replace(/javascript/i, "JavaScript");
document.write(text);

document.write('<br>');
document.write('<br>');
var name = '"a", "b"';
name.replace(/"([^"]*)"/g, "'$1'");
document.write(name);

console.log(removeRepeat(a));
//消除数组中重复的数据
function removeRepeat(arr){
   var newArra=[];
   // arr.map(function(item){
   //   if(newArra.indexOf(item)===-1){
   //      newArra.push(item);
   //   }
   // });
 for(index in arr){  //item为索引 for in
   if(newArra.indexOf(arr[index])===-1){
     newArra.push(arr[index]);
   }
 }

 for(item of arr){
   if(newArra.indexOf(item)===-1){
     newArra.push(item);
   }
 }

   return newArra;
}


//有一个长度为100的数组，值为其所在位置的索引
var a1=new Array(100);
a1.join(";").split(";").map(function(item,index){
   return index;
});
console.log(a1);


//算出数组前10位元素之和
var sum=a.slice(0,10).reduce(function(pre,cur){
   return pre+cur;
});
console.log(sum);

//对数组进行乱序排列
console.log(a.sort(function(num1,num2){
  var sign=(Math.random()>0.5)?1:-1;
  return (num1-num2)*sign;
}));
